home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / turbovis / tvtool17.zip / TOOLS.H < prev    next >
C/C++ Source or Header  |  1993-10-25  |  21KB  |  796 lines

  1. /*  Copyright (C) 1993   Marc Stern  (internet: stern@mble.philips.be)  */
  2.  
  3. #ifndef __Tools_H
  4. #define __Tools_H
  5.  
  6. #include "c2cpp.h"
  7. #include <stdio.h>
  8. #include <io.h>
  9. #include <dos.h>
  10.  
  11.  
  12. /* for Microsoft (or other than Borland) */
  13.  
  14. #ifndef MK_FP
  15. #define MK_FP( seg, ofs )   (void far *)( (unsigned long)((void far *)(seg)) + (unsigned long)((void near *)(ofs)) )
  16.  
  17. struct  fcb {
  18.     char    fcb_drive;      /* 0 = default, 1 = A, 2 = B */
  19.     char    fcb_name[8];    /* File name */
  20.     char    fcb_ext[3];     /* File extension */
  21.     short   fcb_curblk;     /* Current block number */
  22.     short   fcb_recsize;    /* Logical record size in bytes */
  23.     long    fcb_filsize;    /* File size in bytes */
  24.     short   fcb_date;       /* Date file was last written */
  25.     char    fcb_resv[10];   /* Reserved for DOS */
  26.     char    fcb_currec;     /* Current record in block */
  27.     long    fcb_random;     /* Random record number */
  28. };
  29.  
  30. struct  xfcb    {
  31.     char        xfcb_flag;    /* Contains 0xff to indicate xfcb */
  32.     char        xfcb_resv[5];  /* Reserved for DOS */
  33.     char        xfcb_attr;     /* Search attribute */
  34.     struct  fcb xfcb_fcb;      /* The standard fcb */
  35. };
  36.  
  37. #endif
  38.  
  39.  
  40.             
  41. typedef unsigned char BYTE;
  42.  
  43.  
  44. /***
  45.  *  Function    :  HIBYTE/LOWBYTE
  46.  *
  47.  *  Description :  Extract high/low byte of an integer
  48.  *
  49.  *  Parameters  :  in   int x
  50.  *
  51.  *  Side-effects:  Macro, so be careful.
  52.  *
  53.  *  Return      :  none
  54.  ***/
  55.  
  56. #define HIBYTE( x )   ( (unsigned int)(x) >> 8 )
  57. #define LOWBYTE( x )  ( (unsigned char)(x) )
  58.  
  59.  
  60. /***
  61.  *  Function    :  CAST
  62.  *
  63.  *  Description :  Cast any object to any type.
  64.  *
  65.  *  Parameters  :  in     new_type      any type
  66.  *                 in     object        any variable
  67.  *
  68.  *  Side-effects:  Macro, so be careful.
  69.  *
  70.  *  Return      :  none
  71.  ***/
  72.  
  73. #define CAST( new_type, object ) ( *((new_type *)&object) )
  74.      
  75.  
  76. /***
  77.  *  Function    :  SWAP
  78.  *
  79.  *  Description :  Swap two arguments of any type.
  80.  *
  81.  *  Parameters  :  in/out   x      any type argument
  82.  *                 in/out   y      any type argument
  83.  *
  84.  *  Side-effects:  Macro, so be careful.
  85.  *
  86.  *  Return      :  none
  87.  ***/
  88.  
  89. #define SWAP( x, y )        ( (x) ^= (y) ^= (x) ^= (y) )
  90.  
  91.  
  92. /***
  93.  *  Function    :  fileexist
  94.  *
  95.  *  Description :  Test if a filename exist
  96.  *
  97.  *  Parameters  :  in   char *filename
  98.  *
  99.  *  Return      :  0 or 1
  100.  ***/
  101.  
  102. #define fileexist( filename )   ( ! access(filename, 0) )
  103.  
  104.  
  105. /***
  106.  *  Function    :  ICA_get/put
  107.  *
  108.  *  Description :  Intra-application Communications Area get/put
  109.  *                 a 16 bytes data
  110.  *
  111.  *  Parameters  :  in   void *ptr   pointer to a 16 bytes data
  112.  *
  113.  *  Return      :  none
  114.  ***/
  115.  
  116. #define ICA_get( ptr )   ( memcpy(ptr, MK_FP(0x0040, 0x00F0), 16) )
  117. #define ICA_put( ptr )   ( memcpy(MK_FP(0x0040, 0x00F0), ptr, 16) )
  118.  
  119.  
  120.  
  121. /***
  122.  *  Function    :  getkey
  123.  *
  124.  *  Description :  Return a 2-bytes key pressed.
  125.  *
  126.  *  Parameters  :  none
  127.  *
  128.  *  Decisions   :  extended characters are added to 256.
  129.  *
  130.  *  Return code :  code of key pressed.
  131.  *
  132.  *  OS/Compiler :  MS-DOS
  133.  ***/
  134.  
  135. EXTERN int getkey( void );
  136.  
  137.  
  138. /***
  139.  *  Function    :  ungetkey
  140.  *
  141.  *  Description :  Puts a 2-bytes key into the keyboard buffer
  142.  *
  143.  *  Parameters  :  in    int key           key to be buffered
  144.  *
  145.  *  Decisions   :  extended characters are added to 256.
  146.  *
  147.  *  Return code :  none
  148.  *
  149.  *  Warning     :  May not work if a keyboard buffer extender is used.
  150.  *                 Does not handle the case of buffer full.
  151.  *
  152.  *  OS/Compiler :  MS-DOS
  153.  ***/
  154.  
  155. EXTERN void ungetkey( int key );
  156.  
  157.  
  158.  
  159. /***
  160.  *  Function    :   inputkey
  161.  *
  162.  *  Description :   return a 2-bytes key pressed
  163.  *                  (extended characters are added to 256).
  164.  *
  165.  *  Parameters  :   in       int    timeout     maximum time (seconds) waiting
  166.  *                                              before a key is pressed
  167.  *
  168.  *
  169.  *  Decisions   :   If no key is hit before timeout (in seconds)
  170.  *                  the function returns 0.
  171.  *                  timeout -1 means no timeout.
  172.  *                  timeout  0 means check for type-ahead.
  173.  *
  174.  *  Return      :   -1 if time-out
  175.  *
  176.  *  OS/Compiler :   MS-DOS
  177.  ***/
  178.  
  179. EXTERN int inputkey( int timeout );
  180.  
  181.  
  182. /***
  183.  *  Function    :  fnreduce
  184.  *
  185.  *  Description :  Transforms a filename into a full reduced filename.
  186.  *
  187.  *  Parameters  :  in/out   char *filename    input/reduced filename
  188.  *
  189.  *  Decisions   :  Translate into uppercase
  190.  *                  '/' are tranlated into '\\'
  191.  *
  192.  *  Return      :  pointer to result
  193.  *
  194.  *  OS/Compiler :  MS-DOS
  195.  ***/
  196.  
  197. EXTERN char *fnreduce( char *filename );
  198.  
  199.  
  200. /***
  201.  *  Function    :  getpgmpath
  202.  *
  203.  *  Description :  Transforms a filename into a full pathname
  204.  *                 relative to program directory.
  205.  *
  206.  *  Parameters  :  in/out   char *filename    input filename
  207.  *
  208.  *  Return      :  pointer to filename    
  209.  *
  210.  *  Precond     :  Global variable extern char **_argv must be defined
  211.  *                 and assign to argv in main( int argc, char *argv[] )
  212.  *                 Built-in in Borland
  213.  *                 Built-in in Microsoft (uses _pgmptr)
  214.  *
  215.  *  OS/Compiler :  MS-DOS version >= 3.0
  216.  ***/
  217.  
  218. EXTERN char *getpgmpath( char *filename );
  219.  
  220.  
  221. /***
  222.  *  Function    :  gettmppath
  223.  *
  224.  *  Description :  Transforms a filename into a full pathname
  225.  *                 relative to temporary directory.
  226.  *
  227.  *  Decisions   :  Temporary directory is first searched
  228.  *                 into environment variable 'TEMP',
  229.  *                 after into environment variable 'TMP'.
  230.  *                 If none are defined, 'C:\' is assumed.
  231.  *
  232.  *  Parameters  :  in/out  char *filename    filename
  233.  *
  234.  *  Return      :  pointer to filename
  235.  *
  236.  *  Precond     :  Global variable extern char **_argv must be defined
  237.  *                 and assign to argv in main( int argc, char *argv[] )
  238.  *                 Built-in in Borland
  239.  *
  240.  *  OS/Compiler :  MS-DOS version >= 3.0
  241.  ***/
  242.  
  243. EXTERN char *gettmppath( char *filename );
  244.  
  245.  
  246. /***
  247.  *  Function    :  truename
  248.  *
  249.  *  Description :  Transforms a filename into a full reduced filename.
  250.  *                 Resolves all SUBST's, JOIN's, network names,...
  251.  *
  252.  *  Parameters  :  in/out   char *filename    input/reduced filename
  253.  *
  254.  *  Warning     :   - Valid only for DOS >= 2.0
  255.  *                  - Trailing '\' is not removed
  256.  *
  257.  *  Return      :  0      OK
  258.  *                 2  Invalid syntax
  259.  *                 3  Invalid drive or path
  260.  *
  261.  *  OS/Compiler :  MS-DOS version >= 2.0
  262.  ***/
  263.  
  264. EXTERN int truename( char *filename );
  265.  
  266.  
  267. /***
  268.  *  Function    :  exthandles
  269.  *
  270.  *  Description :  Allows MS-DOS program to open 255 handles
  271.  *
  272.  *  Parameters  :  none
  273.  *
  274.  *  Return      :  none
  275.  *
  276.  *  OS/Compiler :  MS-DOS version >= 3.30
  277.  ***/
  278.  
  279. EXTERN void exthandles( void );
  280.  
  281.  
  282.  
  283. /***
  284.  *  Function    :  getdensity
  285.  *
  286.  *  Description :  Return the density of a floppy drive.
  287.  *
  288.  *  Parameters  :  in    int drive         0 = A:, 1 = B:
  289.  *
  290.  *  Return      :  density in Kb (360, 720, 1200, 1440, 2880)
  291.  *                 0 if invalid drive or drive not ready
  292.  *                                        
  293.  *  Warning     :  This function does not work correctly
  294.  *                 with 8086/8088 processors
  295.  *
  296.  *  OS/Compiler :  MS-DOS
  297.  ***/
  298.  
  299. EXTERN int getdensity( int drive );
  300.  
  301.  
  302. /***
  303.  *
  304.  *  Function   :    test_drive
  305.  *
  306.  *  Topics     :    Test the availability of a drive.
  307.  *
  308.  *  Parameters :    in    int drive         0 = A:, 1 = B:, 2 = C:,...
  309.  *
  310.  *  Return code:    combination (bitwise OR) of
  311.  *                  D_READABLE
  312.  *                  D_WRITEABLE
  313.  *                  D_NOFORMAT
  314.  *                  D_INVALID
  315.  *                  D_NOTINSERTED
  316.  *                  D_REMOVABLE
  317.  *                  D_SUBST
  318.  *                  D_REMOTE
  319.  *                  D_RAM
  320.  *
  321.  *  OS/Compiler :   MS-DOS version >= 3.10
  322.  ***/
  323.  
  324. EXTERN int test_drive( int drive );
  325.  
  326. #define D_READABLE    (1<<0)
  327. #define D_WRITEABLE   (1<<1)
  328. #def